//
//  RCConVerViewController.m
//  ECO
//
//  Created by zl on 2019/9/26.
//  Copyright © 2019 谷银行. All rights reserved.
//

#import "RCConVerViewController.h"

@interface RCConVerViewController ()<HMDownloadTableViewCellDegate>
/*!
 消息Cell的数据模型
 */
@property(strong, nonatomic) RCMessageModel *model;
@end

@implementation RCConVerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // 头像为圆形
    [self setMessageAvatarStyle:RC_USER_AVATAR_CYCLE];
    //     更新导航栏返回按钮中显示的未读消息数
    [self notifyUpdateUnreadMessageCount];
//    self.view.backgroundColor = [UIColor colorWithHexString:@"#FFFFFF"];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(TextTongzhi:)name:@"TextTongzhi" object:nil];
    
    //    注册自定义测试消息Cell
    [self registerClass:[LLBShopDetailMessageCell class] forMessageClass:[LLBDetailMessage class]];
    [self registerClass:[LLBWithdrawalMessageCell class] forMessageClass:[LLBWithdrawalMessage class]];
}
- (void)rightBtn{
    NSLog(@"+++++点击了右侧");
    DetailsViewController *Details = [[DetailsViewController alloc]init];
    Details.YhUserId = self.targetId;
    [self.navigationController pushViewController:Details animated:YES];
}
- (void)notifyUpdateUnreadMessageCount {
    if (self.allowsMessageCellSelection) {
        [super notifyUpdateUnreadMessageCount];
        return;
    }
    dispatch_async(dispatch_get_main_queue(), ^{
        UIBarButtonItem *right = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"nav_icon_more"] style:UIBarButtonItemStylePlain target:self action:@selector(rightBtn)];
        self.navigationItem.rightBarButtonItem = right;
    });
}
// 输入框文本通知
- (void)TextTongzhi:(NSNotification *)text{
    self.chatSessionInputBarControl.inputTextView.text = text.userInfo[@"name"];
}
- (void)viewWillLayoutSubviews{
    [super viewWillLayoutSubviews];
    // 自定义按钮
    [self.chatSessionInputBarControl.pluginBoardView removeItemAtIndex:0];
    [self.chatSessionInputBarControl.pluginBoardView removeItemAtIndex:1];
    [self.chatSessionInputBarControl.pluginBoardView removeItemAtIndex:2];
    // 加号按钮位置   (自定义快捷回复)
    self.chatSessionInputBarControl.additionalButton.frame = CGRectMake(15, 6, 75, 36);
    ShortcutView *Short = [[ShortcutView alloc]initWithFrame:CGRectMake(0, 0, self.chatSessionInputBarControl.pluginBoardView.frame.size.width , self.chatSessionInputBarControl.pluginBoardView.frame.size.height)];
    Short.backgroundColor = [UIColor colorWithHexString:@"#F6F6F6"];
    [self.chatSessionInputBarControl.pluginBoardView addSubview: Short];
//     自定义表情按钮位置
    [self.chatSessionInputBarControl.emojiButton mas_updateConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.chatSessionInputBarControl);
        make.right.equalTo(self.chatSessionInputBarControl).offset(-15);
        make.width.height.equalTo(@(30));
    }];
    // 自定义输入框位置
    [self.chatSessionInputBarControl.inputTextView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.chatSessionInputBarControl).offset(105);
        make.centerY.equalTo(self.chatSessionInputBarControl);
        make.right.equalTo(self.chatSessionInputBarControl.emojiButton.mas_left).offset(-15);
        make.height.equalTo(@(36));
    }];
    
}
// 发送自定义消息
- (void)shareTableViewCellNeedDelete:(NSDictionary *)dic{
    LLBDetailMessage *testMessage = [[LLBDetailMessage alloc]init];
    testMessage.detail = dic;
    
    [[RCIM sharedRCIM]sendMessage:ConversationType_PRIVATE targetId:self.chatSessionInputBarControl.targetId content:testMessage pushContent:nil pushData:nil success:^(long messageId) {
        NSLog(@"+++%ld",messageId);
    } error:^(RCErrorCode nErrorCode, long messageId) {
        NSLog(@"nErrorCode:  %ld",(long)nErrorCode);
    }];
}
// Tabbar隐藏
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    // 隐藏加号
//    self.chatSessionInputBarControl.additionalButton.hidden = YES;
    // 隐藏录音,和切回键盘
    self.chatSessionInputBarControl.recordButton.hidden = YES;
    self.chatSessionInputBarControl.switchButton.hidden = YES;
    self.tabBarController.tabBar.hidden = YES;
}
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    if([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    }
}
@end
